<?php

namespace app\admin\controller;

use app\common\model\AdminModel;
use qrcode\QRcode;
use think\facade\View;
use think\facade\Cache;
class PublicController extends Base
{

    protected $request;

    /**
     * 不需登录方法
     * @var array
     */
    protected $noLogin = ['*'];

    /**
     * 构造方法
     * @access public
     * @throws \Exception
     */
    public function __construct()
    {
        parent::__construct();
        $this->request   = app()->request;
    }

    /**
     * 用户登录
     * @return string
     * @throws \Exception
     */
    public function login()
    {

        $adminModel = new AdminModel();
        $data = $this->request->param();
        $this->validate($data,[
            'mobile|手机号' => 'require|mobile',
            'password|密码'  => 'require',
            //'vcode|验证码'    => 'require',
        ]);
        //if (!captcha_check($data['vcode'], 0)) exception('验证码错误');
        $ret = $adminModel->login($data['mobile'], $data['password']);
        Cache::set('system_token-'.$ret['info']['id'] ,$ret['token']);
        $this->result($ret,'登录成功',1);
    }

    /**
     * 提醒页面
     * @return string
     */
    public function tips(){
        $msg = $this->request->param('msg/s','');
        View::assign('msg',$msg);
        return View::fetch();
    }

    /*二维码*/
    public function qrcode(){
        $text = $this->request->param('text');
        $qrcode = Qrcode::png(html_out($text));
        return response($qrcode, 200, ['Content-Length' => strlen($qrcode)])->contentType('image/png');
    }


}